package com.mes.schedule.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.mes.basicdata.domain.Calendar;
import com.mes.basicdata.domain.CalendarData;



/**
 * 日历
 * 
 * @author Administrator
 * @version 3.0
 * @created lcs 2017-03-18
 */
public class SCalendar extends Calendar implements Serializable {

	// 应该放在日历对象中

	/**
	 * 单班日历
	 */
	public static final String DEFAULT_CALENDAR_STANDARD_ONESHIFT = "SYSDC1";
	/**
	 * 双班日历
	 */
	public static final String DEFAULT_CALENDAR_STANDARD_TWOSHIFT = "SYSDC2";
	/**
	 * 24小时日历
	 */
	public static final String DEFAULT_CALENDAR_STANDARD_24H = "SYSDC24";
	private static final long serialVersionUID = 1L;
	/**
	 * 加班工作
	 */
	public final static int CALENDAR_OVERTIME = 2;
	/**
	 * 正常工作
	 */
	public final static int CALENDAR_NOMAL = 1;
	/**
	 * 不工作
	 */
	public final static int CALENDAR_CLOSINGTIME = 0;
	/**
	 * 放假
	 */
	public final static int CALENDAR_BREAKDOWN = -1;

	private ScheduleScheme scheme;
	private Date startDate;

	private Date endDate;

	/**
	 * 每周几天的日历情况，已经考虑了基准日历之后
	 */
	private CalendarData[] weekDayCalendarData = new CalendarData[7];
	/**
	 * 这段时间的例外情况，已经考虑了基准日历之后
	 */

	private List<CalendarData> exceptionCalendarData = new ArrayList<CalendarData>();

	/**
	 * //本身日历 的例外数据
	 */

	private List<CalendarData> selfExceptionCalendarData = new ArrayList<CalendarData>();
	/**
	 * //本身日历 每周几天的日历情况
	 */

	private List<CalendarData> selfWeekDayCalendarData = new ArrayList<CalendarData>();

	/**
	 * 表达日历能力 其实应该用二维数据，表达可用系数 2014-9-28,改称动态grid,便于日历自动扩展
	 */
	protected Map<Integer, Integer> timeGrid = new HashMap<Integer, Integer>();
	/**
	 * 时间片段和班次属性的对应定义 by hba
	 */
	protected Map<Integer, Integer> shiftGrid = new HashMap<Integer, Integer>();
	/**
	 * 时间片段和班次的对应定义 by hba
	 */
	protected Map<Integer, Shift> shiftProductionGrid = new HashMap<Integer, Shift>();
	
	protected List<ScheduleCalendarQuote> scheduleCalendarQuoteList;
	/**
	 * 上次初始化截止日期
	 */
	protected Date initEndDate;

	/**
	 * //是否存在例外日历 如果没有例外，本日历将无须初始化，直接计算
	 */
	protected boolean sameWithBase;
	/**
	 * //是否无能力
	 */
	protected boolean noCapacity;

	public SCalendar() {
	}

	/**
	 * @return the startDate
	 */
	public Date getStartDate() {
		return startDate;
	}

	/**
	 * @param startDate
	 *            the startDate to set
	 */
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	/**
	 * @return the endDate
	 */
	public Date getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate
	 *            the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "编号:" + this.getUuid() + " 名称：" + this.getCalendarName();
	}

	public CalendarData[] getWeekDayCalendarData() {
		return weekDayCalendarData;
	}

	public void setWeekDayCalendarData(CalendarData[] weekDayCalendarData) {
		this.weekDayCalendarData = weekDayCalendarData;
	}

	public List<CalendarData> getExceptionCalendarData() {
		return exceptionCalendarData;
	}

	public void setExceptionCalendarData(
			List<CalendarData> exceptionCalendarData) {
		this.exceptionCalendarData = exceptionCalendarData;
	}

	public ScheduleScheme getScheme() {
		return scheme;
	}

	public void setScheme(ScheduleScheme scheme) {
		this.scheme = scheme;
	}

	public List<CalendarData> getSelfExceptionCalendarData() {
		return selfExceptionCalendarData;
	}

	public void setSelfExceptionCalendarData(
			List<CalendarData> selfExceptionCalendarData) {
		this.selfExceptionCalendarData = selfExceptionCalendarData;
	}

	public List<CalendarData> getSelfWeekDayCalendarData() {
		return selfWeekDayCalendarData;
	}

	public void setSelfWeekDayCalendarData(
			List<CalendarData> selfWeekDayCalendarData) {
		this.selfWeekDayCalendarData = selfWeekDayCalendarData;
	}

	public void destroy() {
		try {
			if (this.weekDayCalendarData != null)
				this.weekDayCalendarData = null;
			// 这段时间的例外情况，已经考虑了基准日历之后
			if (this.exceptionCalendarData != null) {
				this.exceptionCalendarData.clear();
				this.exceptionCalendarData = null;
			}
			if (this.selfExceptionCalendarData != null) {
				this.selfExceptionCalendarData.clear();
				this.selfExceptionCalendarData = null;
			}
			if (this.selfWeekDayCalendarData != null) {
				this.selfWeekDayCalendarData.clear();
				this.selfWeekDayCalendarData = null;
			}
			if (this.timeGrid != null) {
				this.timeGrid.clear();
				this.timeGrid = null;
			}

			if (this.shiftGrid != null) {
				this.shiftGrid.clear();
				this.shiftGrid = null;
			}

			this.scheme = null;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Map<Integer, Integer> getTimeGrid() {
		return timeGrid;
	}

	public Map<Integer, Integer> getShiftGrid() {
		return shiftGrid;
	}

	public void setShiftGrid(Map<Integer, Integer> shiftGrid) {
		this.shiftGrid = shiftGrid;
	}

	public void setTimeGrid(Map<Integer, Integer> timeGrid) {
		this.timeGrid = timeGrid;
	}

	public Date getInitEndDate() {
		return initEndDate;
	}

	public void setInitEndDate(Date initEndDate) {
		this.initEndDate = initEndDate;
	}

	public boolean getSameWithBase() {
		return sameWithBase;
	}

	public void setSameWithBase(boolean sameWithBase) {
		this.sameWithBase = sameWithBase;
	}

	public boolean getNoCapacity() {
		return noCapacity;
	}

	public void setNoCapacity(boolean noCapacity) {
		this.noCapacity = noCapacity;
	}

	public Map<Integer, Shift> getShiftProductionGrid() {
		return shiftProductionGrid;
	}

	public void setShiftProductionGrid(Map<Integer, Shift> shiftProductionGrid) {
		this.shiftProductionGrid = shiftProductionGrid;
	}

}